/* 
 *   Classname:  datapower.ExportToCSV
 * 
 *   Date       Developer   Description
 *   Nov 28, 2017    周成功              新建
 *
 */
package demo.database.mssql;

import java.sql.Connection;
import java.util.HashSet;
import java.util.Set;

import com.titan.core.utils.data.FormatUtils;
import com.titan.core.utils.db.DBUtils;
import com.titan.core.utils.db.RecordSet;

/**
 *
 *
 * @author 周成功
 *
 */
public class SelectTables {
    public static void main(String[] args) {
        Connection conn = null;
        try {
            String ip  = "192.168.128.213";
            String port  = "1433";
            String dbname  = "H20170913";
            String username = "sa";
            String password = "123456";
          
            conn = DBUtils.getMSSQLConnection(ip, port, dbname, username, password, true);
            
            run(conn);
        } catch(Exception ex) {
            ex.printStackTrace();
        } finally {
            DBUtils.close(conn);
        }
    }
    private static void run3(Connection conn) throws Exception {
        String sql = "select count(*) from (select distinct userid from member)";
        System.out.println(DBUtils.getValue(conn, sql));  // 27170
    }    
    private static void run(Connection conn) throws Exception {
//        String sql = "select id,uid,userID,userName,pwd1,pwd2,pwd3 from member";
        String sql = "select id,uid,userID,userName,pwd1,pwd2,pwd3 from member where userid='17773319697'";
//        String sql = "select Class from Actions";
        Set<String> cache = new HashSet<String>();
        RecordSet rest = DBUtils.executeQueryToRecordSet(conn, sql);
        while(rest.moveNext()) {
//            String value = rest.getString("USERID");
//            if(cache.contains(value)) {
//                System.out.println(value);
//            } else {
//                cache.add(value);
//            }
            System.out.println(FormatUtils.to4Digit(rest.getCursor()) + "\t" + rest.toMap());
        }
    }
}
